package org.execute.tool.日期处理;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 提取秒 和毫秒
 */
public class extractSecondsMilliseconds {
    public static void main(String[] args) {
        DateTimeFormatter secondsFormatter = DateTimeFormatter.ofPattern("ss");
        DateTimeFormatter millisFormatter = DateTimeFormatter.ofPattern("SS");
        LocalDateTime now = LocalDateTime.now();
        // 提取秒和毫秒字符串
        String secondsStr = now.format(secondsFormatter);  // 如 "22"
        String millisStr = now.format(millisFormatter);    // 如 "123"
        // 转换为数值并计算总毫秒
        int seconds = Integer.parseInt(secondsStr);
        int millis = Integer.parseInt(millisStr);
        int totalMillis = seconds * 1000 + millis;
        String result = String.format("%06d", totalMillis);
        System.out.println(result);  // 输出 "000022123"
    }
}
